perm filename TEXF20.SAI[ARK,TEX] blob sn#570086 filedate 1984-09-04 generic text, type T, neo UTF8
comment  This module is TENEX/TOPS-20 compatible.  

comment First generated by LTP on MAY-1-79, later modified by DRF;
comment	At SUAI, all editors always leave a crlf at the end of every line.
	TEX's input routines assume that no input file will end with other
	than a crlf.  On Tops20, it is possible to have a file of text that
	does not end with a crlf (or cr, or lf even), so we need to check
	every time we do an input to see if the file ended without finding
	a crlf, in which case we supply one and turn off the eof indicator.
	The next input will cause the eof flag to be turned back on.
;
saf string array fname[0:2] # file directory, name, and extension;

procedure scanfilename # sets up fname[0:2];
begin	label name!is!in;
		procedure append (reference string s);
		begin
			if curcmd = spacer then go to name!is!in;
			if curcmd >= charcodes then begin
			  backerror ("Blank space should follow file name");
			  go to name!is!in;
			end;
		    s := s & curchar;
		    getnctok;
		end;

	fname[0]←fname[1]←fname[2]←null;
	getnctok;
	while true do begin
		if curchar = "<" then begin
			while curchar neq ">" do append (fname[0]);
			append (fname[0]);	#  appends the ">";
		end;

		while curchar neq "." and curchar neq ":" do append (fname[1]);

		if curchar=":" then begin 
			fname[0]←fname[1]; append(fname[0]); 
			fname[1]:= null end
		else done;
	end;

	while true do append (fname[2]);
name!is!in:

end;

internal procedure inputfile;
begin comment "\input" has just been scanned. This procedure scans
	the user's file name, employing naming conventions common to both 
	TENEX and TOPS-20, then reads in the first line and feeds it to the
	input system;
integer chan;
label abort # if something goes wrong trying to read the file;
string flname;
boolean firsttry;

define checkeof=⊂ comment could be dummy eof, with a partial line left;
	IF EOF AND LENGTH(INBUF)>0 THEN BEGIN
		INBUF←INBUF&'15 # PUT IN DUMMY CR ON INPUT;
		BRCHAR←'15 # CONVINCE CODE BELOW ABOUT IT;
		EOF←0 # CATCH IT NEXT TIME;
		END;
	if eof then begin print(")");go to abort end⊃;

firsttry←true;

    while true do begin
	scanfilename;
	if fname[2]=0 then fname[2]←".TEX" # default extension;
	flname←fname[0]&fname[1]&fname[2];

	if (chan:= openfile (flname,"RE")) < 0  and  fname[0] = 0  then begin
		comment if lookup failed and no explicit directory was given,
			try default library area;
		flname := libraryarea & flname;
		chan := openfile (flname, "RE");
	end;

	if chan<0 
	  then begin
		error("Open failed on file "&flname);
		if firsttry
		   then begin	firsttry←false;	continue; end
		   else
			return;
	       end
	  else		done;
    end;

print(" (",flname);
pushinput # save present file status;
state←newline; recovery←chan; filename←flname;

setinput (chan, 150, brchar, eof);
inbuf←input(chan,crffbreak) # get first line of file;

# DRF ;			IF EOF AND LENGTH(INBUF)>0 THEN BEGIN
				INBUF←INBUF&'15 # PUT IN DUMMY CR ON INPUT;
				BRCHAR←'15 # CONVINCE CODE BELOW ABOUT IT;
				EOF←0 # CATCH IT NEXT TIME;
				END;

checkeof; print(" 1");

if equ(inbuf[1 to 9],"COMMENT ⊗") then
	begin comment Skip TVedit directory page;
	while brchar neq '14 and not eof do inbuf←input(chan,ffbreak);
	checkeof;
	inbuf←input(chan,crffbreak) # get first line of second page;
	checkeof; print(" 2");
	loc ← (2 lsh infod) + 1 # page 2 line 1;
	end
else	loc ← (1 lsh infod) + 1 # page 1 line 1;

if (tracing land '20) and not_nonstop then
	begin integer p # garbage bin;
	if inbuf='12 then p←lop(inbuf);
	if length(inbuf)=1 then inbuf←" "&inbuf;
	print(nextline);
	outstr(inbuf[1 to ∞-1]) # show inbuf on screen;
				begin string s; s←inchwl;
				if s then inbuf←s&inbuf[∞ to ∞];
				end;
	inbuf←inchwl&inbuf[∞ to ∞];
	end;
curbuf←inbuf;

comment Now define the output file name if it hasn't yet been defined;
if ofilname=0 then declareofil(fname[1]&ofilext) # no explicit directory here;
return;

abort: release(chan);
popinput;
end;

internal integer procedure opendigit(integer d) # Do this after "\open d =";
begin integer chan; string s;
scanfilename;
if fname[2]=0 then fname[2]←".TEX"; s←fname[0]&fname[1]&fname[2];
while (chan:=openfile(s,"WE"))<0 do
		begin print(nextline,"I can't write on file ",s);
		if not not_nonstop then quit;
		print(nextline,"Output file for \open "&d&" = ");
		s←intty;
		end;
return(chan);
end;